home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Technology Seed / ADC Seed CD - July 1999.toast / USB / Mac OS USB DDK v1.2 / Examples / PrinterClassDriver / Utils.cp < prev    next >
Encoding:
Text File  |  1999-04-15  |  2.8 KB  |  134 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Utils.cp
  3.  
  4.     Contains:    General utilities
  5.  
  6.  
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History:
  11.  
  12.         22 Mar 98     gp        Created
  13.  
  14.     To Do:
  15. */
  16. #include "Utils.h"
  17.  
  18.  
  19. /*-----------------------------------------------------------------------------*
  20.  
  21.     PStrEqualCaseInsensitive
  22.     
  23.     Desc:        Compares two Pascal strings while ignoring case
  24.  
  25.     In:            string1 - string to compare
  26.                 string2 - string to compare
  27.     Out:        none
  28.     
  29.     History:
  30.  
  31.     22 Mar 98    gp        Added.
  32.     
  33. *-----------------------------------------------------------------------------*/
  34. Boolean PStrEqualCaseInsensitive( Str255 string1, Str255 string2 )
  35. {
  36.     short    x;
  37.     char    c1, c2;
  38.     
  39.     if ( string1[0] != string2[0] )
  40.         return( false );
  41.         
  42.     for ( x=1; x<=string1[0]; x++ )
  43.     {
  44.         c1 = string1[x];
  45.         c2 = string2[x];
  46.         if ( c1 != c2 )
  47.         {
  48.             c1 &= ~32;
  49.             c2 &= ~32;
  50.             if ( (c1>='A') && (c1<='Z') && (c1 != c2) )
  51.                 return( false );
  52.         }
  53.     }
  54.     return( true );
  55. }
  56.  
  57. /*-----------------------------------------------------------------------------*
  58.  
  59.     AppendPStr
  60.     
  61.     Desc:        Copy a PASCAL style string to the source
  62.  
  63.     In:            mainStr - string to append to
  64.                 addStr - string to append
  65.     Out:        none
  66.     
  67.     History:
  68.  
  69.     22 Mar 98    gp        Added.
  70.     
  71. *-----------------------------------------------------------------------------*/
  72. void AppendPStr(StringPtr mainStr, StringPtr addStr)
  73.     {
  74.     register short    i;
  75.     register unsigned char    *pMainStr    = (unsigned char *)&mainStr[mainStr[0] + 1];
  76.     register unsigned char    *pAddStr    = (unsigned char *)&addStr[1];
  77.     register short    addLength    = (unsigned char)addStr[0];
  78.  
  79.     if (addLength)
  80.         {
  81.         // limit the ultimate length to 255 bytes
  82.         if ( ((unsigned char)mainStr[0] + addLength) > 255)
  83.             addLength    = 255 - (unsigned char)mainStr[0];
  84.  
  85.         // do the copy
  86.         for (i = 0; i < addLength; ++i)
  87.             *pMainStr++    = *pAddStr++;
  88.  
  89.         // update the count
  90.         mainStr[0]    += addLength;
  91.         }
  92.     }
  93.  
  94. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95.     
  96.     NameRegistryInstalled
  97.     
  98.     Desc:    Copies the contents of cell in the list hList into the string
  99.             pointed to by theString. The string is converted to a Pascal-
  100.             style string, with a preceding length byte.
  101.         
  102.         It is assumed that cell is a valid cell, that the cell contains no
  103.         more than 255 characters, and that theString and hList are not nil.
  104.  
  105.  
  106.     In:            Pointer to storage for a string.
  107.                 Coordinates of cell in list
  108.                 Handle to list
  109.  
  110.     Out:        String containing copy of cell text
  111.     
  112.     History:
  113.  
  114.             22 Mar 98    gp        Added.
  115. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  116. void GetNameFromCell (StringPtr theString, Cell cell, ListHandle hList)
  117. {
  118.     short length;
  119.     
  120.     /*
  121.     The maximum length of the string is the size of a Str255, minus the
  122.     length byte…
  123.     */
  124.     length = sizeof(Str255) - 1;
  125.  
  126.     LGetCell((StringPtr)(theString + 1), &length, cell, hList);
  127.     
  128.     /*
  129.     Set the length byte.
  130.     */
  131.     *theString = (unsigned char) length;
  132. };
  133.  
  134.